package org.nfyszny.zzzs.modules.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoDict;
import org.jeecg.common.system.query.QueryGenerator;
import org.nfyszny.zzzs.modules.entity.ZzzsRecordEnterprise;
import org.nfyszny.zzzs.modules.service.IZzzsRecordEnterpriseService;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;

import org.jeecg.common.system.base.controller.JeecgController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.aspect.annotation.AutoLog;

/**
 * @Description: 企业备案
 * @Author: jeecg-boot
 * @Date: 2022-11-11
 * @Version: V1.0
 */
@Api(tags = "企业备案")
@RestController
@RequestMapping("/modules/zzzsRecordEnterprise")
@Slf4j
public class ZzzsRecordEnterpriseController extends JeecgController<ZzzsRecordEnterprise, IZzzsRecordEnterpriseService> {


    @Autowired
    private IZzzsRecordEnterpriseService zzzsRecordEnterpriseService;

    @AutoLog(value = "企业备案-列表")
    @ApiOperation(value = "企业备案-列表", notes = "企业备案-列表")
    //@RequiresPermissions("org.nfyszny.zzzs:zzzs_record_of_supply_ability:delete")
    @GetMapping(value = "/list")
    public Result<List<ZzzsRecordEnterprise>> list() {
        List<ZzzsRecordEnterprise> list = zzzsRecordEnterpriseService.list();
        return Result.TOK(list);
    }

    @AutoLog(value = "企业备案-修改备案")
    @ApiOperation(value = "企业备案-修改备案", notes = "企业备案-修改备案")
    //@RequiresPermissions("org.nfyszny.zzzs:zzzs_record_of_supply_ability:delete")
    @PutMapping(value = "/change")
    public Result<String> change(@RequestBody ZzzsRecordEnterprise zzzsRecordEnterprise) {
        zzzsRecordEnterpriseService.change(zzzsRecordEnterprise);
        return Result.TOK("删除成功!");
    }

    @AutoLog(value = "企业备案-修改备案")
    @ApiOperation(value = "企业备案-修改备案", notes = "企业备案-修改备案")
    //@RequiresPermissions("org.nfyszny.zzzs:zzzs_record_of_supply_ability:delete")
    @PutMapping(value = "/review")
    public Result<String> review(@RequestBody ZzzsRecordEnterprise zzzsRecordEnterprise) {
        zzzsRecordEnterpriseService.review(zzzsRecordEnterprise);
        return Result.TOK("删除成功!");
    }

    /**
     * getHaveInfoById
     */
    @ApiOperation(value = "产品备案-查询已备案完成的备案信息", notes = "产品备案-查询已备案完成的备案信息")
    @GetMapping(value = "/getHaveInfoById")
    public Result<ZzzsRecordEnterprise> getHaveInfoById(@RequestParam(name = "id", required = true) String id) {
        ZzzsRecordEnterprise zzzsRecordEnterprise = zzzsRecordEnterpriseService.getHaveInfoById(id);
        if (zzzsRecordEnterprise == null) {
            return Result.error("未找到对应数据");
        }
        return Result.TOK(zzzsRecordEnterprise);
    }

    /**
     * 分页列表查询
     *
     * @param zzzsRecordEnterprise
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    //@AutoLog(value = "企业备案-分页列表查询")
    @ApiOperation(value = "企业备案-分页列表查询", notes = "企业备案-分页列表查询")
    @GetMapping(value = "/pageList")
    public Result<IPage<ZzzsRecordEnterprise>> queryPageList(ZzzsRecordEnterprise zzzsRecordEnterprise,
                                                             @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                             @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                             HttpServletRequest req) {
        QueryWrapper<ZzzsRecordEnterprise> queryWrapper = QueryGenerator.initQueryWrapper(zzzsRecordEnterprise, req.getParameterMap());
        Page<ZzzsRecordEnterprise> page = new Page<ZzzsRecordEnterprise>(pageNo, pageSize);
        IPage<ZzzsRecordEnterprise> pageList = zzzsRecordEnterpriseService.page(page, queryWrapper);
        return Result.TOK(pageList);
    }

    /**
     * 根据公司id分页列表查询
     *
     * @param zzzsRecordEnterprise
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    //@AutoLog(value = "企业备案-分页列表查询")
    @ApiOperation(value = "企业备案-分页列表查询", notes = "企业备案-分页列表查询")
    @GetMapping(value = "/getListByCompanyId")
    @AutoDict
    public Result<IPage<ZzzsRecordEnterprise>> getListByCompanyId(ZzzsRecordEnterprise zzzsRecordEnterprise,
                                                                  @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                                  @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                                  HttpServletRequest req) {
        QueryWrapper<ZzzsRecordEnterprise> queryWrapper = QueryGenerator.initQueryWrapper(zzzsRecordEnterprise, req.getParameterMap());
        Page<ZzzsRecordEnterprise> page = new Page<ZzzsRecordEnterprise>(pageNo, pageSize);
        IPage<ZzzsRecordEnterprise> pageList = zzzsRecordEnterpriseService.getListByCompanyId(queryWrapper, page);
        return Result.TOK(pageList);
    }

    /**
     * 申请备案
     *
     * @param zzzsRecordEnterprise
     * @return
     */
    @AutoLog(value = "企业备案-申请备案")
    @ApiOperation(value = "企业备案-申请备案", notes = "企业备案-申请备案")
    //@RequiresPermissions("org.nfyszny.zzzs:zzzs_record_enterprise:add")
    @PostMapping(value = "/add")
    public Result<String> add(@RequestBody ZzzsRecordEnterprise zzzsRecordEnterprise) {
        zzzsRecordEnterpriseService.saveRecordEnterpriseInfo(zzzsRecordEnterprise);
        return Result.TOK("添加成功！");
    }


    /**
     * 保存备案信息
     *
     * @param zzzsRecordEnterprise
     * @return
     */
    @AutoLog(value = "企业备案-保存备案信息")
    @ApiOperation(value = "企业备案-保存备案信息", notes = "企业备案-保存备案信息")
    //@RequiresPermissions("org.nfyszny.zzzs:zzzs_record_enterprise:add")
    @PostMapping(value = "/saveFiling")
    public Result<String> saveFiling(@RequestBody ZzzsRecordEnterprise zzzsRecordEnterprise) {
        zzzsRecordEnterpriseService.saveFiling(zzzsRecordEnterprise);
        return Result.TOK("添加成功！");
    }

    @AutoLog(value = "企业备案-获取该企业的备案状态")
    @ApiOperation(value = "企业备案-获取该企业的备案状态", notes = "企业备案-获取该企业的备案状态")
    //@RequiresPermissions("org.nfyszny.zzzs:zzzs_record_enterprise:add")
    @GetMapping(value = "/getEnterpriseStatus")
    public Result getEnterpriseStatus() {

        Map<String, Object> map = zzzsRecordEnterpriseService.getEnterpriseStatus();
        return Result.TOK(map);
    }
//    /**
//     * 获取登录用户的企业备案是否完成
//     */
//    @AutoLog(value = "企业备案-获取该企业的备案状态")
//    @ApiOperation(value = "企业备案-获取该企业的备案状态", notes = "企业备案-获取该企业的备案状态")
//    //@RequiresPermissions("org.nfyszny.zzzs:zzzs_record_enterprise:add")
//    @GetMapping(value = "/getEnterpriseSuccessStatus")
//    public Result getEnterpriseSuccessStatus() {
//
//        Boolean aBoolean= zzzsRecordEnterpriseService.getEnterpriseSuccessStatus();
//        return Result.TOK(aBoolean);
//    }

    /**
     * 编辑
     *
     * @param zzzsRecordEnterprise
     * @return
     */
    @AutoLog(value = "企业备案-编辑")
    @ApiOperation(value = "企业备案-编辑", notes = "企业备案-编辑")
    //@RequiresPermissions("org.nfyszny.zzzs:zzzs_record_enterprise:edit")
    @RequestMapping(value = "/edit", method = {RequestMethod.PUT, RequestMethod.POST})
    public Result<String> edit(@RequestBody ZzzsRecordEnterprise zzzsRecordEnterprise) {
        zzzsRecordEnterpriseService.updateById(zzzsRecordEnterprise);
        return Result.TOK("编辑成功!");
    }

    /**
     * 通过id删除
     *
     * @param id
     * @return
     */
    @AutoLog(value = "企业备案-通过id删除")
    @ApiOperation(value = "企业备案-通过id删除", notes = "企业备案-通过id删除")
    //@RequiresPermissions("org.nfyszny.zzzs:zzzs_record_enterprise:delete")
    @DeleteMapping(value = "/delete")
    public Result<String> delete(@RequestParam(name = "id", required = true) String id) {
        zzzsRecordEnterpriseService.removeById(id);
        return Result.TOK("删除成功!");
    }

    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @AutoLog(value = "企业备案-批量删除")
    @ApiOperation(value = "企业备案-批量删除", notes = "企业备案-批量删除")
    //@RequiresPermissions("org.nfyszny.zzzs:zzzs_record_enterprise:deleteBatch")
    @DeleteMapping(value = "/deleteBatch")
    public Result<String> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
        this.zzzsRecordEnterpriseService.removeByIds(Arrays.asList(ids.split(",")));
        return Result.TOK("批量删除成功!");
    }

    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    //@AutoLog(value = "企业备案-通过id查询")
    @ApiOperation(value = "企业备案-通过id查询", notes = "企业备案-通过id查询")
    @GetMapping(value = "/queryById")
    public Result<ZzzsRecordEnterprise> queryById(@RequestParam(name = "id", required = true) String id) {
        ZzzsRecordEnterprise zzzsRecordEnterprise = zzzsRecordEnterpriseService.getById(id);
        if (zzzsRecordEnterprise == null) {
            return Result.error("未找到对应数据");
        }
        return Result.TOK(zzzsRecordEnterprise);
    }

    /**
     * 通过公司编号查询
     *
     * @param id
     * @return
     */
    //@AutoLog(value = "企业备案-通过id查询")
    @ApiOperation(value = "企业备案-通过id查询", notes = "企业备案-通过id查询")
    @GetMapping(value = "/getEnterpriseByCompanyId")
    public Result<ZzzsRecordEnterprise> getEnterpriseByCompanyId(@RequestParam(name = "id", required = true) String id) {
        ZzzsRecordEnterprise zzzsRecordEnterprise = zzzsRecordEnterpriseService.getById(id);
        if (zzzsRecordEnterprise == null) {
            return Result.error("未找到对应数据");
        }
        return Result.TOK(zzzsRecordEnterprise);
    }


    /**
     * 导出excel
     *
     * @param request
     * @param zzzsRecordEnterprise
     */
    //@RequiresPermissions("org.nfyszny.zzzs:zzzs_record_enterprise:exportXls")
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, ZzzsRecordEnterprise zzzsRecordEnterprise) {
        return super.exportXls(request, zzzsRecordEnterprise, ZzzsRecordEnterprise.class, "企业备案");
    }

    /**
     * 通过excel导入数据
     *
     * @param request
     * @param response
     * @return
     */
    //@RequiresPermissions("zzzs_record_enterprise:importExcel")
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, ZzzsRecordEnterprise.class);
    }

}
